﻿using System;
using System.Data;
using System.Web.UI;
using VitCode.Castle.DataAccess;
using VitCode.Web.UI;
using VitCode.Web.UI.WebControls;

namespace VitCode.Web.BackStageManagement
{
    public partial class PermissionSet : VcPage
    {
        private readonly CastleAccess acc = new CastleAccess();
        private string sql = " SELECT Id,Name,Alias,Memo from VitCode_Castle_Role";

        protected void Page_Load(object sender, EventArgs e)
        {
            Response.Write("<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>");
            if (String.IsNullOrEmpty(GenericContext.CurrUserCode))
            {
                Response.Redirect("../Default.aspx");
            }
            ListGridInfo.DataSourceDelegate = new PaginationGrid.GridDataSourceDelegate(BindList);
            ListGridInfo.BindGrid();
         
        }
 
    
        public object BindList()
        {
            DataTable dt = acc.GetDataTableBySql(sql);
            return dt;
        }

        protected void ListGridInfo_OnGridItemSelect(object sender, PaginationGridItemSelectArgs e)
        {
            string val = e.SelectedDataKeyValue;
            var win = new Window(Page, "分配菜單許可權") {Height = 700, Width = 800, Scrollbars = true, Status = true};
            win.ShowModalDialog("GroupMenu.aspx?&CurrentRole=" + val, new string[] { "hdCheckInfo" });
        }

        protected void btnQuery_Click1(object sender, EventArgs e)
        {

            if (ddlCondition.SelectedItem.Text != "" && txtValue.Text.Trim().Length > 0)
            {
                sql = "  SELECT Id,Name,Alias,Memo from VitCode_Castle_Role where ";
                if (rbtAmount.Checked)
                    sql += ddlCondition.SelectedItem.Value + " = '" + txtValue.Text.Trim() + "'";
                else sql += ddlCondition.SelectedItem.Value + " like '%" + txtValue.Text.Trim() + "%'";

                ListGridInfo.DataSourceDelegate = new PaginationGrid.GridDataSourceDelegate(BindList);
                ListGridInfo.BindGrid();
            }
            else
            {
                sql =
                    " SELECT Id,Name,Alias,Memo from VitCode_Castle_Role";
                ListGridInfo.DataSourceDelegate = new PaginationGrid.GridDataSourceDelegate(BindList);
                ListGridInfo.BindGrid();
            }
        }

    }
}
